<!DOCTYPE html>
<html>
<?php $this->load->view('admin/public/header.html');?>
<body class="childrenBody" style="width:50%;">
<form class="layui-form layui-row layui-col-space10">
	<div class="layui-col-md9 layui-col-xs12">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md12 layui-col-xs7">
				<div class="layui-form-item magt3">
					<label class="layui-form-label">角色名称</label>
					<input type="hidden" name="roleId">
					<div class="layui-input-block">
						<input type="text" class="layui-input title" name="roleName" lay-verify="require" placeholder="请输入角色名称">
					</div>
				</div>
				<div class="layui-form-item magt3">
					<label class="layui-form-label">角色简介</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input title" name="roleBrief" lay-verify="require" placeholder="请输入角色介绍">
					</div>
				</div>
				
				<div class="layui-form-item magt3">
					<label class="layui-form-label">添加权限</label>
					<div class="layui-input-block">
						
						<?php foreach($auth as $key=>$val):?>
							<input type="checkbox" name="auth[]" class="auths"  lay-verify="require" title="<?php echo $val['intro']?>" value="<?php echo $val['authId']?>">
						<?php endforeach;?>
			
					</div>
			</div>
				
			<div class="layui-right">
				<a class="layui-btn layui-btn-sm" lay-filter="addrole" lay-submit><i class="layui-icon">&#xe609;</i>保存</a>
			</div>
		
			</div>
			
		</div>
		
	</div>	
</form>
<script type="text/javascript">
layui.use(['form','layer','layedit','laydate','upload'],function(){
	var form=layui.form, $=layui.jquery;
	
	form.verify({
	    require : function(val){
	        if(val == ''){
	            return "必填项不能为空";
	        }
	    },
	})
	form.on("submit(addrole)",function(data){
    	
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        
        $.ajax({
        	type:'post',
        	data:data.field,
        	url:'editrole',
        	dataType: "json", 
        	success:function(res){
        		if(res==200){
        			top.layer.close(index);
                    top.layer.msg("添加成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
        		}else{
        			top.layer.close(index);
                    top.layer.msg("添加失败！");
        		}
        	},
        	fail:function(){
        		top.layer.close(index);
                top.layer.msg("添加失败！");
        	}
        })        
        
    })
})

</script>
</body>
</html>